package com.report.entity;

import lombok.Setter;
import lombok.Getter;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Getter
@Setter
@IdClass(ReportId.class)
@Table(
        name = "report"
)
public class Report {
    @Id
    private Integer id;
    /**
     * 项目编号
     */
    private String sjxmbh;
    /**
     * 被审计单位信用代码
     */
    private String bsdwxydm;
    /**
     * 报表类型
     */
    private String reporttype;
    /**
     * 合并类型
     * @see com.report.enumeration.MergeTypeEnum
     */
    @Column(name = "merge_type")
    private Integer mergeType;
    /**
     * 报表信息(JSON格式)
     */
    @Column(columnDefinition = "TEXT")
    private String reportinfo;
    // 创建时间，默认当前时间
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    // 更新时间，默认当前时间
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    // 删除时间
    @Column(name = "deleted_at")
    private LocalDateTime deletedAt;

    // 在插入之前设置创建时间和更新时间
    @PrePersist
    protected void onCreate() {
        LocalDateTime now = LocalDateTime.now();
        createdAt = now;
        updatedAt = now;
    }

    // 在更新之前设置更新时间
    @PreUpdate
    protected void onUpdate() {
        updatedAt = LocalDateTime.now();
    }
}
